<?php

/**
* This is your child theme's functions.php file.
* Use this to write any custom functions you may need.
* You can use this to hook into the Hybrid theme (could also create a plugin to do the same).
*/

/*
* Constant paths
*/
define( IMT_GREEN, get_stylesheet_directory() );
define( IMT_GREEN_URL, get_stylesheet_directory_uri() );

    /*
    * Make sure to localize all your text if you plan on releasing this publicly
    *
    * @reference http://codex.wordpress.org/Translating_WordPress
    */
load_theme_textdomain('oneblue', IMT_GREEN);

    /*
    * Add actions
    *
    * @reference http://themehybrid.com/themes/hybrid/hooks
    * @reference http://codex.wordpress.org/Plugin_API/Action_Reference
    */
//add_action('init', 'imt_is_wap');
add_action('publish_post', 'publish_post_2_qzone', 0);
add_action('init', 'imt_load_comment');
add_action( 'wp_head', 'one_remove_actions' );
//add_action( 'hybrid_head', 'one_front_page_template' );
//add_action( 'hybrid_before_html', 'get_sliding_panel' );//需要插件支持~
add_action( 'hybrid_after_single','one_post_info' );
add_action( 'hybrid_head', 'imt_js');
add_action( 'hybrid_before_page_nav', 'hybrid_search_form' );
add_action( 'hybrid_header', 'one_get_header_widget', 11 );
add_action( 'hybrid_header', 'imt_taotao');
add_action( 'hybrid_header', 'hybrid_page_nav',12);
add_action( 'hybrid_before_comment', 'imt_comment_info_detector' );
add_action( 'hybrid_after_comment', 'one_replyTo' );
//add_action( 'hybrid_after_comment_list', 'imt_comments_tip' );
//add_action( 'hybrid_before_comment_form', 'imt_comment_put' );
add_action( 'hybrid_after_container', 'one_widget_container', 11 );
add_action( 'widgets_init', 'one_register_widget_areas' );
add_action( 'hybrid_footer', 'one_footer_insert' );

    /*
    * Add filters
    *
    * @reference http://themehybrid.com/themes/hybrid/filters
    * @reference http://codex.wordpress.org/Plugin_API/Filter_Reference
    */
add_filter( 'hybrid_post_meta_boxes', 'one_post_meta_boxes' );
//add_filter( 'wp_page_menu_args', 'news_page_menu_args' );


/**
* 移除Hybrid主题默认的actions
*
* @since 0.1
*/
function one_remove_actions() {
remove_action( 'hybrid_after_container', 'hybrid_get_primary' );
remove_action( 'hybrid_after_container', 'hybrid_get_secondary' );
remove_action( 'hybrid_footer', 'hybrid_footer_insert' );
remove_action( 'hybrid_after_single', 'custom_field_series');
remove_action( 'hybrid_after_header', 'hybrid_page_nav' );
remove_action( 'hybrid_before_comment', 'hybrid_avatar' );
}

/**
 * Add additional post meta boxes.
 * - Feature image input box.
 *
 * @since 0.1
 */
function one_article_series() {
	global $post;
	$series = get_post_meta($post->ID, 'Series', true);
	if($series) :
		$args = array(
			'numberposts' => -1,
			'meta_key' => 'Series',
			'meta_value' => $series,
		);
		$series_posts = get_posts($args);
		if($series_posts) :
			$class = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $series);
			$class = strtolower(str_replace(array(' ', '&nbsp;'), '-', $class));
			echo '<div class="series series-' . $class . '"><h4 class="series-title">' . __('这个系列的日志') . '</h4><ul>';
			foreach($series_posts as $serial) :
				if($serial->ID == $post->ID)
					echo '<li class="current-post">' . $serial->post_title . '</li>';
				else
					echo '<li><a href="' . get_permalink($serial->ID) . '" title="' . str_replace('"', '"', $serial->post_title) . '">' . str_replace('"', '"', $serial->post_title) . '</a></li>';
			endforeach;
			echo '</ul></div>';
		endif;
	endif;
}

/**
 * Add additional post meta boxes.
 * - Feature image input box.
 *
 * @since 0.1
 */
function one_footer_insert() {?>

&copy; 2005-2009 <?php echo '<a class="site-link" href="' . get_bloginfo( 'url' ) . '" title="' . get_bloginfo( 'name' ) . '" rel="home"><span>' . get_bloginfo( 'name' ) . '</span></a>'; ?>, <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/">content license</a>.<br />
Powered by<a class="wp-link" href="http://wordpress.org" title="Powered by WordPress, state-of-the-art semantic personal publishing platform"><span>WordPress</span></a> and <?php $data = get_theme_data( TEMPLATEPATH . '/style.css' );
	echo '<a class="hybrid-link theme-link" href="' . $data['URI'] . '" title="' . __('Hybrid Theme Framework', 'hybrid') . '"><span>' . __('Hybrid', 'hybrid') . '</span></a>'; ?> , Based on <a href="http://cordobo.com/" title="Free WordPress Themes">Cordobo Green Park 2</a>, Redesigned by <?php $data = get_theme_data( STYLESHEETPATH . '/style.css' );
	echo '<a class="child-link" href="' . $data['URI'] . '" title="' . $data['Name'] . '"><span>' . $data['Name'] . '</span></a>'; ?>.<br />
Validate <a href="http://validator.w3.org/check/refererr" title="Extensible HyperText Markup Language"><span>XHTML</span></a> or <a href="http://jigsaw.w3.org/css-validator/check/referer" title="Cascading Style Sheets"><span>CSS</span></a>.<a href="http://www.miibeian.gov.cn" rel="nofollow" ><span>蜀ICP备09022942号</span></a>,<script type="text/javascript" src="http://www.nasboq.com/stat?id=4351&amp;sid=it"></script> &amp;
<script type="text/javascript" src="http://js.users.51.la/2903564.js"></script>
<noscript><a href="http://www.51.la/?2903564"><img alt="我要啦免费统计" src="http://img.users.51.la/2903564.asp" style="border:none" /></a></noscript>.<br />
<?php 
	if ( current_user_can( 'switch_themes' ) )
		$out = sprintf( __('This page loaded in %1$s seconds with %2$s database queries.', 'hybrid'), timer_stop( 0, 3 ), get_num_queries() );
	echo $out;
	if ( is_singular() )
		$redirect = get_permalink();

	if ( is_user_logged_in() )
		$out = '<a href="' . wp_logout_url( $redirect ) . '" title="' . __('Log out of this account', 'hybrid') . '">' . __('Log out', 'hybrid') . '</a>';
	else
		$out = '<a href="' . wp_login_url( $redirect ) . '" title="' . __('Log into this account', 'hybrid') . '">' . __('Log in', 'hybrid') . '</a>';

	echo $out; ?>
<?php
}

/**
* Add additional post meta boxes.
* - Feature image input box.
*
* @since 0.1
*/
function one_post_meta_boxes( $meta_boxes ) {
$meta_boxes['medium'] = array( 'name' => 'Medium', 'default' => '', 'title' => __('Medium/Feature:', 'one'), 'type' => 'text', 'show_description' => false, 'description' => false );
return $meta_boxes;
}

/**
* Shows an author description after the post.
* Only shows on single post.
*
* @since 0.1
*/
function one_post_info() {
?>
<div class="entry-after">
    <h2>Burn after reading<span> » Now you're done reading. What's next?</span></h2>
    <div class="author-profile vcard">
        <?php echo get_avatar( get_the_author_email(), '96'); ?>
        <h4 class="author-name fn n"><?php the_author_posts_link(); ?></h4>
        <p class="author-description author-bio">
            <?php the_author_description(); ?>
        </p>
    </div>
    <div class="entry-related">
        <?php wp_related_posts();?>
    </div>
    <div class="entry-onther">
        <h3>日志信息</h3>

        <p>如需转载烦请添加以下信息: 本文内容转载自<a title="::冰封::" href="http://im-t.net"><strong>砼砼's blog</strong></a>[http://im-t.net].<br />
            如喜欢这篇文章或者本站,建议您<span class="one-rss"><strong><a target="_blank" title="订阅本站您将第一时间获得最新文章" href="http://im-t.net/feed">RSS订阅</a></strong></span>本站,以及时地获取更多精彩内容!
        </p>
        <p>可以通过订阅<?php post_comments_feed_link('Comments RSS 2.0'); ?> feed，一直不断的跟踪这篇日志的的评论~<br />
            <?php if ( comments_open() && pings_open() ) {
                // Both Comments and Pings are open ?>
            欢迎您点击<strong><a href="#respond">发表评论</a></strong>参与这篇日志的讨论，如果您需要引用或者转载此文，请确保让我知道，并建议使用<strong><a href="<?php trackback_url(); ?>" rel="trackback">trackback</a></strong>将转载信息通知到本页面。

        <?php } elseif ( !comments_open() && pings_open() ) {
        // Only Pings are Open ?>
            这篇日志的讨论系统已经关闭~, 如果您需要引用或者转载此文，请确保让我知道，并建议使用<strong><a href="<?php trackback_url(); ?>" rel="trackback">trackback</a></strong>将转载信息通知到本页面。

        <?php } elseif ( comments_open() && !pings_open() ) {
        // Comments are open, Pings are not ?>
            欢迎您点击<strong><a href="#respond">发表评论</a></strong>参与这篇日志的讨论， Pinging现在是关闭状态~

        <?php } elseif ( !comments_open() && !pings_open() ) {
        // Neither Comments, nor Pings are open ?>
            这篇日志禁止进行任何讨论和Pinging。

        <?php }?></p>
    </div>
	<?php custom_field_series();?>
</div>
<?php
}

/**
* Wraps the Primary, Secondary, Tertiary, fourth widget sections
* Calls each section
*
* @since 0.1
*/
function one_widget_container() {
if ( !is_page_template( 'no-widgets.php' ) ) :
echo '<div id="widget-container">';
hybrid_get_primary();
hybrid_get_secondary();
echo '</div>';
endif;
}

/**
* Register additional widget areas
*
* @since 0.1.1
*/
function one_register_widget_areas() {
register_sidebar( array( 'name' =>  __('Utility: oneHeader', 'one'), 'id' => 'utilityheader', 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
}

/**
* Displays the 公共组件: 头部 widget section
*
* @since 0.1
*/
function one_get_header_widget() {
if ( is_sidebar_active( __('Utility: oneHeader', 'one') ) ) :
echo '<div id="utility-header" class="utility">';
dynamic_sidebar( __('Utility: oneHeader', 'one') );
echo '</div>';
endif;
}

/**
* Adds JavaScript and CSS to Front Page page template
* Also removes the breadcrumb menu
*
* @since 0.1
*/
function one_front_page_template() {
if ( is_page_template( 'front-page.php' ) ) :
wp_enqueue_script( 'slider', IMT_GREEN_URL . '/js/jquery.cycle.js', array( 'jquery' ), 0.1 );
wp_enqueue_script( 'slider-functions', IMT_GREEN_URL . '/js/jquery.functions.js', array( 'jquery' ), 0.1 );
wp_enqueue_style( 'front-page', IMT_GREEN_URL . '/css/front-page.css', false, '0.1', 'screen' );
remove_action( 'hybrid_before_content', 'hybrid_breadcrumb' );
endif;
}

function imt_comment_put() {
	if($_COOKIE["comment_author_" . COOKIEHASH]!=""){?>
		<div id="imt-welcome" style="margin-left:8px;">
			<?php printf(__('欢迎<strong>%s</strong>童鞋回归，继续在这片热土上插上你的小红花吧...'), $_COOKIE["comment_author_" . COOKIEHASH]) ?> 		
		<span  id="imt_show_author_info" style="cursor: pointer; color:#2970A6;">换个马甲？ &raquo;</span>
		<span  id="imt_hide_author_info" style="cursor: pointer;color: #2970A6;">修改完成 &raquo;</span>
		</div>
	<script type="text/javascript">//<![CDATA[
		jQuery(document).ready(function(){
			jQuery("#commentform .form-author,#commentform .form-email,#commentform .form-url,#commentform .form-imtqq,#imt_hide_author_info").hide();
			jQuery("#imt_show_author_info").click(function(){
				jQuery("#commentform .form-author,#commentform .form-email,#commentform .form-url,#commentform .form-imtqq").animate({height:"toggle",opacity: "toggle" }); 
				jQuery("#imt_hide_author_info").show();
				jQuery("#imt_show_author_info").hide();
			});
			jQuery("#imt_hide_author_info").click(function(){
				jQuery("#commentform .form-author,#commentform .form-email,#commentform .form-url,#commentform .form-imtqq").animate({height:"toggle",opacity: "toggle" }); 
				jQuery("#imt_hide_author_info").hide();
				jQuery("#imt_show_author_info").show();
			});
		});		
		//]]>
	</script>
<?php } 
}

function one_replyTo() { ?>
	<span class="one_replyTo" >
		<span title="回复通知这南瓜。" onclick='one_replyTo("<?php comment_ID(); ?>", "<?php comment_author();?>")' style="cursor: pointer;" class="add">
			<img alt="Notify" src="http://im-t.net/wp-content/plugins/mailtocommenter/notify.png"/>
		</span>
	</span><?php
}
function imt_comments_tip() { ?>
<script type="text/javascript">//<![CDATA[
$imt(document).ready(function() { 

var A=/^#comment-/;
var B=/^@/;
if($imt('#comments li p a').text().match(B) && $imt('#comments li p a').attr('href').match(A)){
	$imt('#comments li p a').addClass('tip-atreply');
};

$imt('.tip-atreply').hover(function() {
	var target = this;
	var _commentId = $imt(this).attr('href');
 
	if($imt(_commentId).is('.comment')) {
		$imt('<li class="comment-tip"></li>').hide().html($imt(_commentId).html()).appendTo($imt('ol.comment-list'));
		$imt('ol.comment-list .comment-tip').css({
			left:$imt().cumulativeOffset(this)[0] + $imt(this).width() + 10,
			top:$imt().cumulativeOffset(this)[1] - 22
		}).fadeIn();
	} else {
		var id = _commentId.slice(9);
		$imt.ajax({
			type:         'GET'
			,url:         '?action=load_comment&id=' + id
			,cache:       false
			,dataType:    'html'
			,contentType: 'application/json; charset=utf-8'
 
			,beforeSend: function(){
				$imt('<li class="comment-tip"></li>').hide().html('<p class="ajax-loader msg">Loading...</p>').appendTo($imt('ol.comment-list'));
				$imt('ol.comment-list .comment-tip').css({
					left:$imt().cumulativeOffset(target)[0] + $imt(target).width() + 10,
					top:$imt().cumulativeOffset(target)[1] - 22
				}).fadeIn();
			}
 
			,success: function(data){
				var addedComment = $imt(data);
				addedComment.hide().appendTo($imt('ol.comment-list'));
				$imt('ol.comment-list .comment-tip').html(addedComment.html());
			}
 
			,error: function(){
				$imt('ol.comment-list .comment-tip').html('<p class="msg">Oops, failed to load data.</p>');
			}
		});
	}
}, function() {
	$imt('ol.comment-list .comment-tip').fadeOut(400, function(){
		$imt(this).remove();
	});
});
})
</script><?php
}
function imt_js() { 
	//echo $_SERVER["HTTP_USER_AGENT"]; 
	/*if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 6.0") && !strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0")  && !strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0") ) {
		wp_enqueue_style( 'imtcss', IMT_GREEN_URL . '/css/screen-ie6.css', false, '0.1', 'screen' );
	}else{
		wp_enqueue_style( 'imtcss', IMT_GREEN_URL . '/css/screen.css', false, '0.1', 'screen' );
	}*/
	//wp_register_script('jquerycorner', IMT_GREEN_URL.'/js/jquery.corner.js', false, '1.9.9');
	//wp_enqueue_script('jquerycorner', false, false, '1.9.9');
	//wp_register_script('imtoneblue', IMT_GREEN_URL.'/js/imt.one.blue.js', false, '0.1');
	//wp_enqueue_script('imtoneblue', false, false, '0.1');
	if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 6.0") && !strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0")  && !strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0") ) {
		wp_register_script('imtoneblue', 'http://letskillie6.googlecode.com/svn/trunk/letskillie6.bilingual.pack.js', false, '0.1');
		wp_enqueue_script('imtoneblue', false, false, '0.1');
	}else{
	}?>
	<script type="text/javascript">//<![CDATA[
		var imt_mysite_url= '<?php echo IMT_GREEN_URL.'/' ?>';//]]>
	</script><?php
	if($_COOKIE["comment_author_" . COOKIEHASH]!=""){ ?>
		<script type="text/javascript">
			document.title = "<?php printf(__('%s童鞋, 欢迎回来！你正在浏览： '), $_COOKIE["comment_author_" . COOKIEHASH]) ?>" + document.title
		</script><?php 
	}
	if (is_single()||is_page() && !is_page_template( 'front-page.php' )){
		wp_enqueue_script("jquery");
		wp_enqueue_script("prototype");
		wp_register_script('commentsajax', IMT_GREEN_URL.'/js/comments-ajax.js', false, '0.1');
		wp_enqueue_script('commentsajax', false, false, '0.1');
		wp_register_script('commentstip', IMT_GREEN_URL.'/js/comments-tip.js', false, '0.2');
		wp_enqueue_script('commentstip', false, false, '0.2');
		wp_register_script('blockUI', IMT_GREEN_URL.'/js/jquery.blockUI.js', false, '2.23');
		wp_enqueue_script('blockUI', false, false, '2.23');?>
		<script type="text/javascript">//<![CDATA[
			function one_replyTo(commentID,author) {
				var inReplyTo='@<a href="#comment-'+commentID+'">'+author+':<\/a>';
				var myField;
				if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
					myField = document.getElementById('comment');
				} else {
					return false;
				}
				if (document.selection) {
					myField.focus();
					sel = document.selection.createRange();
					sel.text = inReplyTo;
					myField.focus();
				}
				else if (myField.selectionStart || myField.selectionStart == '0') {
					var startPos = myField.selectionStart;
					var endPos = myField.selectionEnd;
					var cursorPos = endPos;
					myField.value = myField.value.substring(0, startPos)
						+ inReplyTo
						+ myField.value.substring(endPos, myField.value.length);
					cursorPos += inReplyTo.length;
					myField.focus();
					myField.selectionStart = cursorPos;
					myField.selectionEnd = cursorPos;
				}
				else {
					myField.value += inReplyTo;
					myField.focus();
				}
			}
			//]]>
		</script><?php 
	} 
} 
/**
* 滔滔公告～
* 来自 Denis http://fairyfish.net/2008/08/02/taobao/
* taotao($num=1)
*
* @since 0.1
*/

if(!class_exists('http_fetch')){
	function http_fetch($url) {
		if(function_exists('curl_init')) {
			$curl = curl_init($url);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
			$rtrn = curl_exec($curl);
			curl_close($curl);
		} else {
			$rtrn = file_get_contents($url);
		}	
		return $rtrn;
	}
}
function taotao($num=10){
	$qq = "156888120";//这里填你的QQ号
	$taotao_sr = array('网页', 'QQ机器人', 'QQ空间', 'QQ签名', '短信', '手机上网', 'MSN机器人', 'MSN签名', '手机QQ', '彩信', '订阅', "", 'QQ状态');
	$url = "http://www.taotao.com/cgi-bin/msgMgr?type=3&num=$num&qq=$qq";
	$result = http_fetch($url);
	$xml = simplexml_load_string($result);
	$md = $xml->info->md;
$taotao_string = '';      
    foreach ($md->ml as $ml){  
        $taotao_string .= '<span style="display:block">'.(string)$ml->cn.' '.LJ($ml->t).' 通过 '.$taotao_sr[(string)$ml->sr].'</span>';  
    }  
$taotao_string .= ''; 
	return  $taotao_string;
}
function LJ($t='') {
    $imt_taotao_t_array=explode(",",$t);
    if (count($imt_taotao_t_array) < 2) {
        return "";
    }
    $n = $imt_taotao_t_array[0];
    $v = $imt_taotao_t_array[1];
    $s = '';
    if ($n == 1) {
        $s = '约&nbsp;' .$v. '&nbsp;秒前';
    } else if ($n == 2) {
        $s = '约&nbsp;' .$v. '&nbsp;分钟前';
    } else if ($n == 3) {
        $s = '约&nbsp;' .$v. '&nbsp;小时前';
    } else if ($n == 4) {
        $s = '约&nbsp;1&nbsp;天前';
    } else if ($n == 5) {
        $s = '约&nbsp;3&nbsp;天前';
    } else if ($n == 6) {
        $s = '约&nbsp;1&nbsp;周前';
    } else if ($n == 7) {
        $s = $v;
    }
    return $s;
}
function imt_taotao(){
	global $hybrid_settings;
	$default_avatar='';
	if ( $hybrid_settings['default_avatar'] ){
		$default_avatar = esc_url( $hybrid_settings['default_avatar'] );
	}
	$imt_taotao_string = '';
	$imt_taotao_string .= '<div id=imt-wisdom>';
	$imt_taotao_string .='<div class="headright">';
	$imt_taotao_string .= get_avatar( get_bloginfo('admin_email'), '50', $default_avatar, get_bloginfo( 'description ' ));
	$imt_taotao_string .='</div>';
	$imt_taotao_string .='<div class="diyself">';
	$imt_taotao_string .='<div class="imt-content">';
	$imt_taotao_string .='<div class="wisdom">'.taotao(1).'</div>';
	$imt_taotao_string .='</div>';
	$imt_taotao_string .='</div>';
	$imt_taotao_string .='</div>';
	echo $imt_taotao_string;
}
function imt_is_wap(){
include('mobile_device_detect.php');
mobile_device_detect(true,true,true,true,true,true,'http://mobile.com','http://desktop.com');
}

function imt_comment_info_detector(){
	if (function_exists("CID_init")) { 
		?><span class="one-comment-info">
		<?php
		CID_print_comment_flag(); 
		echo ' '; 
		CID_print_comment_browser(); 
		?>
		</span><?php
	}
}

function imt_load_comment(){
	if($_GET['action'] =='load_comment' && $_GET['id'] != ''){
		$comment = get_comment($_GET['id']);
		if(!$comment) {
			fail(printf('Whoops! Can\'t find the comment with id  %1$s', $_GET['id']));
		}
 
		hybrid_comments_callback($comment, null,null);
		hybrid_comments_end_callback();
		die();
	}
}
function smtp_mailer_qqmail($subject,$body){
    $qq_number = '156888120';
    $qq_password = '198612312';
 
    if ( !class_exists('PHPMailer') ) {
        require_once ABSPATH . WPINC . '/class-phpmailer.php';
        require_once ABSPATH . WPINC . '/class-smtp.php';
    }
    $mail = new PHPMailer();
 
    $mail->IsSMTP();
    $mail->Mailer   = "smtp";
    $mail->CharSet  = 'utf-8';
    $mail->Encoding = 'base64';
    $mail->IsHTML(true);
    $mail->SMTPAuth = true;
    $mail->Host     = "smtp.qq.com";
    $mail->Username = $qq_number."@qq.com";
    $mail->Password = $qq_password;
    $mail->From     = $qq_number."@qq.com";
    $mail->FromName = $qq_number; 
 
    $mail->AddAddress($qq_number."@qzone.qq.com");
    $mail->Subject = $subject;
    $mail->Body    = $body;
    $mail->Send();
}

function publish_post_2_qzone($post_ID){
    $qzone = get_post_meta($post_ID, 'qzone', true);
    if($qzone) return;
 
    $post_title = trim($_POST['post_title']);
    $post_except = trim($_POST['post_except']);
    if($post_except){
        $post_content = $post_except;
    }else{
        $post_content = mb_substr(strip_tags(trim($_POST['post_content'])),0,220);
    }
    $post_content= $post_content.'<br />查看全文：<a href="'.get_permalink($post_ID).'">'.get_permalink($post_ID).'</a>';
 
    smtp_mailer_qqmail($post_title,$post_content);
 
    add_post_meta($post_ID, 'qzone', 'true', true);
}

add_action( 'show_user_profile', 'imt_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'imt_show_extra_profile_fields' );
add_action( 'personal_options_update', 'imt_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'imt_save_extra_profile_fields' );

function imt_show_extra_profile_fields( $user ) { ?>

	<h3>扩展配置信息（仅被当前主题支持）</h3>

	<table class="form-table">

		<tr>
			<th><label for="imtqq">腾讯QQ</label></th>

			<td>
				<input type="text" name="imtqq" id="imtqq" value="<?php echo esc_attr( get_the_author_meta( 'imtqq', $user->ID ) ); ?>" class="regular-text" /><br />
				<span class="description">请输入你的腾讯QQ号码（纯数字）</span>
			</td>
		</tr>

	</table>
<?php }
function imt_save_extra_profile_fields( $user_id ) {
	$imt_user_qq=trim($_POST['imtqq']);
	if ( !current_user_can( 'edit_user', $user_id ) )
		return false;
	if(ereg("^[1-9][0-9]{4,}$",$imt_user_qq)){
		update_usermeta( $user_id, 'imtqq', $imt_user_qq );
	}else{
		update_usermeta( $user_id, 'imtqq', '10000' );}
	
}
add_action( 'hybrid_before_comment', 'imt_avatar' );
add_filter('get_avatar', 'imt_qq_face', 10, 3);
function imt_avatar() {
	global $comment, $hybrid;

	if ( !get_option( 'show_avatars' ) )
		return false;

	/* Get/set some comment variables. */
	$comment_type = get_comment_type();
	$author = esc_html( get_comment_author() );
	$url = esc_url( get_comment_author_url() );

	if ( 'pingback' == $comment_type || 'trackback' == $comment_type ) 
		$default_avatar = THEME_IMAGES . "/{$comment_type}.png";

	$default_avatar = apply_filters( "{$hybrid->prefix}_{$comment_type}_avatar", $default_avatar );

	$avatar = get_avatar( get_comment_author_email(), '80', $default_avatar, $author );
	
	$avatar = imt_qq_face($avatar, get_comment(get_comment_ID()), '80');

	/* If URL input, wrap avatar in hyperlink. */
	if ( $url )
		$avatar = '<a href="' . $url . '" rel="external nofollow" title="' . $author . '">' . $avatar . '</a>';

	echo apply_filters( 'imt_avatar', $avatar );
}
function imt_qq_face($a, $i, $size) {

	$key = "im-t.net is a blog";
	//这里设置关键密钥两个关键密钥必须相同
	$imt_get_qq_face = 'http://im-t.net/qqface.php?&qq=%s';
	//QQ头像地址, %s表示QQ号
	$qq_face_size = false;
	//单独指定QQ头像的大小, false or integer
	
	$qq=get_comment_meta($i->comment_ID, 'imtqq', true);
	if ( !is_object($i) )
		return $a;
	if ( ''!=$qq && '10000'!=$qq) {
		$qq = base64_encode(encrypt($qq,$key));
		$a = preg_replace('/src=\'[^\']*\'/',
			'src=\'' . str_replace('%s', $qq, $imt_get_qq_face) . '\'',
			$a);
		if( $qq_face_size )
			$a = str_replace('\'' . $size . '\'', '\'' . $qq_face_size . '\'', $a);
		return $a;
	}
	return $a;
}

function keyED($txt,$encrypt_key){//密钥生成函数
	$encrypt_key = md5($encrypt_key);
	$ctr=0;
	$tmp = "";
	for ($i=0;$i<strlen($txt);$i++){
	  if ($ctr==strlen($encrypt_key)) $ctr=0;
	  $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
	  $ctr++;
	}
	return $tmp;
}

function encrypt($txt,$key){//加密函数
	srand((double)microtime()*1000000);
	$encrypt_key = md5(rand(0,32000));
	$ctr=0;
	$tmp = "";
	for ($i=0;$i<strlen($txt);$i++){
		if ($ctr==strlen($encrypt_key)) $ctr=0;
		$tmp.= substr($encrypt_key,$ctr,1) .
		(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
		$ctr++;
	}
	return keyED($tmp,$key);
}
?>